#pragma once

#ifndef _ACTOR_H_
#define _ACTOR_H_
#include <memory>
#include <functional>
#include <string>
#include "mailpos.h"
#include "base_type.h"

class ByteBuffer;
typedef std::shared_ptr<ByteBuffer> ByteBufferPtr;
namespace as
{
namespace md
{

	
class FrameWork;
class Actor
{
public:
	typedef std::function<void(ByteBufferPtr&, MailPos&)> ActorHandle;
	Actor(FrameWork *fw, const char *name);
	virtual ~Actor();

	void SetAddr(MailPos addr);
	MailPos& GetAddr();

	uint32 GetPriKey();

	virtual void Send(ByteBufferPtr &buf, MailPos &to);
	virtual void Send(ByteBufferPtr &buf, Actor *to);
	virtual void Send(ByteBufferPtr &buf, const char *toname, int toFrameId);
	virtual void SendAll(ByteBufferPtr &buf);
	const char* GetName() { return name_; }

	void SetActorHandle(ActorHandle fun);
	void ActorMsg(ByteBufferPtr &buf, MailPos &addr);
	std::string GetAddrStr();
	ByteBufferPtr GetPacket();
private:
	FrameWork *fw_;
	const char *name_;
	MailPos addr_;
	ActorHandle fun_;
	ByteBufferPtr cache_packet_;
};















}
}

#endif